package com.naiterui.ehp.bs.emr.vo.health;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.utils.date.DateUtil;
import com.naiterui.ehp.bs.emr.exception.ExceptionCodes;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * @Description 外伤史
 * @Author gongbaoqiang
 * @Date 2020/6/2 2:27 PM
 */
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("外伤史")
public class TraumaVO implements Serializable {
    private static final long serialVersionUID = -1619577465745953952L;

    /**
     * 外伤史
     */
    @ApiModelProperty("选项值")
    private String value;

    /**
     * 外伤详情
     */
    @ApiModelProperty("外伤详情")
    private TraumaDetailVO detail;


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class TraumaDetailVO implements Serializable{

        private static final long serialVersionUID = -4889469628513453706L;
        /**
         * 受伤日期
         */
        @ApiModelProperty("受伤日期")
        @JsonFormat(pattern = DateUtil.DATE_FORMAT)
        private Date date;

        /**
         * 受伤区域
         */
        @ApiModelProperty("受伤区域")
        private String  area;

        /**
         * 诊断
         */
        @ApiModelProperty("诊断")
        private String diagnosis;

        public void validate() throws BusinessException{
            if(date == null || StringUtils.isBlank(area) || StringUtils.isBlank(diagnosis)){
                throw new BusinessException(ExceptionCodes.PATIENT_HEALTH_RECORD_TRAUMA);
            }
        }
    }

    public void validate() throws BusinessException{
        if(StringUtils.isBlank(value)){
            throw new BusinessException(ExceptionCodes.PATIENT_HEALTH_RECORD_TRAUMA);
        }
        if("有".equals(value)){
            detail.validate();
        }
    }
}
